/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class code2 {
    //回文链表
    //数组复制法
    public boolean isPalindrome(ListNode head) {
        List<Integer> list = new ArrayList<>();
        int len = 0;
        while(head != null) {
            len++;
            list.add(head.val);
            head = head.next;
        }

        int first = 0;
        int last = len-1;

        while(first < last) {
            if(list.get(first) != list.get(last)) {
                return false;
            }else {
                first++;
                last--;
            }
        }
        return true;
    }
}